//
//  SeeVideoCell.m
//  Zaker
//
//  Created by lirui on 16/3/10.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SeeVideoCell.h"

@interface SeeVideoCell ()
@property(nonatomic, assign)BOOL collect;

@end
@implementation SeeVideoCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLable = [[BaseLabel alloc]init];
        //        _titleLable.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_titleLable];
      
        
        self.detailLable = [[BaseLabel alloc]init];
        //        _detailLable.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_detailLable];
        
        
        self.likeBtn = [UIButton buttonWithType:UIButtonTypeCustom];//否则会有一个蓝色的条
        [self.contentView addSubview:_likeBtn];
             self.timeImg = [[UIImageView alloc]init];
        //        _timeImg.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_timeImg];
        
        self.timeLable = [[BaseLabel alloc]init];
        //        _timeLable.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_timeLable];
        
        self.playImage = [[UIImageView alloc]init];
        //        _playImage.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_playImage];
               self.playLable = [[BaseLabel alloc]init];
        //        _playLable.backgroundColor = [UIColor magentaColor];
        [self.contentView addSubview:_playLable];
        
        self.commentLable = [[BaseLabel alloc]init];
        //        _commentLable.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:_commentLable];
        
        self.myImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_myImageView];
        self.bofang = [[ UIImageView alloc] init];
        [self.contentView addSubview:_bofang];
        
        self.share = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.contentView addSubview:_share];
       

        
    }
    return  self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.manager =  [CoreDataManager defaults];

    //title
    _titleLable.frame = CGRectMake(10, 10, self.contentView.frame.size.width - 20, self.contentView.frame.size.height / 10);
  
    //detail
    _detailLable.frame = CGRectMake(10, _titleLable.frame.origin.y + _titleLable.frame.size.height, _titleLable.frame.size.width, _titleLable.frame.size.height / 2);
    _detailLable.font = [UIFont systemFontOfSize:14];
   
    //Imageview
    _myImageView.frame = CGRectMake(10, _detailLable.frame.origin.y + _detailLable.frame.size.height + 10, _detailLable.frame.size.width, self.contentView.frame.size.height / 3 * 2);
    _timeImg.image = [UIImage imageNamed:@"iconfont-clock"];
    //timeImage
    _timeImg.frame = CGRectMake(_myImageView.frame.origin.x, _myImageView.frame.size.height + _myImageView.frame.origin.y + 5, 20, 20);
    //timeLable
    self.timeLable.frame = CGRectMake(_timeImg.frame.origin.x + _timeImg.frame.size.width + 2, _timeImg.frame.origin.y, _timeImg.frame.size.width * 2, _timeImg.frame.size.height);
    _timeLable.textColor = [UIColor grayColor];
    _timeLable.font = [UIFont systemFontOfSize:10];
    //playImage
    self.playImage.frame = CGRectMake(_timeLable.frame.origin.x + _timeLable.frame.size.width + 10, _timeImg.frame.origin.y, _timeImg.frame.size.width, _timeImg.frame.size.height);
    _playImage.image = [UIImage imageNamed:@"iconfont-shipin"];
    //playLable
    self.playLable.frame = CGRectMake(_playImage.frame.origin.x + _playImage.frame.size.width + 2, _playImage.frame.origin.y, _timeLable.frame.size.width, _playImage.frame.size.height);
    _playLable.font = [UIFont systemFontOfSize:10];
    _playLable.textColor = [UIColor grayColor];
    //comment
    self.commentLable.frame = CGRectMake(self.contentView.frame.size.width / 4 * 3, _timeImg.frame.origin.y, _timeLable.frame.size.width, _timeLable.frame.size.height);
    _commentLable.font = [UIFont systemFontOfSize:10];
    _commentLable.textColor = [UIColor grayColor];
    
    _bofang.frame = CGRectMake(0, 0, 50 * WIDTH, 50 * HEIGHT);
    _bofang.center = _myImageView.center;
    _bofang.image =[ UIImage imageNamed:@"iconfont-zhibo"];
    UITapGestureRecognizer *tap = [[ UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [_bofang addGestureRecognizer:tap];
    _bofang.userInteractionEnabled = YES;
    
   
    //likeBtn
    _likeBtn.frame = CGRectMake(self.contentView.frame.size.width - 30, _titleLable.frame.origin.y + 5, 25 * WIDTH, 25 * HEIGHT);
    [_likeBtn setBackgroundImage:[UIImage imageNamed:@"shoucang"] forState:UIControlStateNormal];
    [_likeBtn setBackgroundImage:[UIImage imageNamed:@"shoucang1"] forState:UIControlStateSelected];

    //根据数据库中是否包含该model判断收藏按钮样式
//    _likeBtn.selected = NO;
    NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Video"];
    NSError *error;
    NSArray *arr = [self.manager.managedObjectContext executeFetchRequest:request error:&error];

    for (Video *m in arr) {
        if ([m.title isEqualToString:_model.title]) {
            _likeBtn.selected = YES;
        }else
        {
            _likeBtn.selected = NO;
        }
    }
    


    
    
    //shareBtn
    self.share.frame = CGRectMake(_commentLable.frame.origin.x + _commentLable.frame.size.width + 2, _timeImg.frame.origin.y, 25*WIDTH, 25*HEIGHT);
    [_share setBackgroundImage:[UIImage imageNamed:@"iconfont-fenxiang"] forState:UIControlStateNormal];
}
-(void)tapAction:(UITapGestureRecognizer *)t
{
    [self.delegate playMovie:t];
}
//收藏方法


@end
